﻿using System.Threading;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using System.Windows.Threading;

namespace Albatross.WPF.Common.PubSub {
	/// <summary>
	/// The subscription will invoke using the UI dispatcher thread if they are available.  Otherwise, no action will be performed.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class DispatcherSubscription<T> : Subscription<T> {
		public override void Invoke(object sender, object msg) {
			Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
			if (dispatcher != null) {
				dispatcher.BeginInvoke(new Action<object, T>(OnMsgReceived), sender, Convert(msg));
			}
		}
	}
}
